package com.ideaaedi.plugin.fastcoding.util;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.project.Project;

/**
 * 右下角消息弹出框通知
 *
 * @author JustryDeng
 * @since 2021/12/18 9:27:49
 */
public final class NotifyUtil {
    
    private NotifyUtil() {
        throw new UnsupportedOperationException("Un-support to create instance");
    }
    
    /**
     * 使用NotificationGroupManager.getInstance().getNotificationGroup这种方式获取NotificationGroup之前，需要先在plugin.xml中配置对应的extensions，
     *  如：
     *  <code>
     *     <extensions defaultExtensionNs="com.intellij">
     *         <notificationGroup id="FastCoding.Notify" displayType="BALLOON"/>
     *     </extensions>
     *  </code>
     */
    @SuppressWarnings("MissingRecentApi")
    private static final NotificationGroup FAST_CODING_NOTIFY_GROUP = NotificationGroupManager.getInstance().getNotificationGroup("FastCoding.Notify");
    
    public static final String TITLE = "Fast Coding";
    
    /**
     * 消息
     *
     * @param project
     *         项目
     * @param title
     *         标题
     * @param message
     *         消息
     * @param notificationType
     *         提示类型
     */
    public static void notify(Project project, String title, String message, NotificationType notificationType) {
        try {
            Notification currentNotify = FAST_CODING_NOTIFY_GROUP.createNotification(message, notificationType);
            currentNotify.setTitle(TITLE);
            currentNotify.setSubtitle(title);
            Notifications.Bus.notify(currentNotify, project);
        } catch (Exception e) {
            //
        }
    }
    
    /**
     * 消息
     *
     * @param project
     *         项目
     * @param title
     *         标题
     * @param message
     *         消息
     */
    public static void notify(Project project, String title, String message) {
        NotifyUtil.notify(project, title, message, NotificationType.INFORMATION);
    }
    
}
